import torch
from torchvision import datasets, transforms
from torch.utils.data import DataLoader

# 定义数据预处理
transform = transforms.Compose([
    transforms.Resize((224, 224)),          # 调整图像大小
    transforms.ToTensor(),                 # 转换为张量
    transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])  # 归一化
])

# 数据集路径
dataset_path = 'image-dataset'

# 使用 ImageFolder 加载数据集
dataset = datasets.ImageFolder(root=dataset_path, transform=transform)

# 定义 DataLoader
batch_size = 1
shuffle = False


dataloader = DataLoader(dataset, batch_size=batch_size, shuffle=shuffle)

# 使用数据集
for images, labels in dataloader:
    print(images.shape)  # 输出: torch.Size([batch_size, 3, 224, 224])
    print(labels)  # 输出: torch.Size([batch_size])
    # 在这里进行模型训练或其他操作